package com.umpay.log.mpsp;

import com.google.gson.Gson;
import com.umpay.dict.LoggerDict;
import com.umpay.dto.UMFRequest;
import com.umpay.dto.UMFResponse;
import com.umpay.util.JsonUtil;
import com.umpay.util.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author zhanglz
 * @ClassName: FileLogger
 * @Description:
 * @date 2018/12/13 9:19
 */
public class FileLogger {
    private static final Logger log = LogManager.getLogger(MpspLogger.class);

    public static void info(HttpServletRequest request, HttpServletResponse response) {
        log.info(getMpspMsg(request, response));
    }

    /**
     * 获取简要日志信息
     *
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @param request
     * @param response
     * @return
     */
    private static String getMpspMsg(HttpServletRequest request, HttpServletResponse response) {
        StringBuilder builder = new StringBuilder();
        long begin = (long) request.getAttribute(LoggerDict.START_TIME);
        long time = System.currentTimeMillis() - begin;
        String value = time + "ms";
        builder.append(request.getRequestURL().toString()).append(",");
        builder.append(request.getMethod()).append(",");
        builder.append(request.getAttribute("merId")).append(",");
        builder.append(request.getAttribute(value));
//        log.info("mpspLog="+builder.toString());
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }
}
